<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta name="author" content="zhaozhenguo">
		<title>礼品规则</title>
		<!--js库及样式-->
		<script LANGUAGE="javascript" src="../script/common.js" type="text/javascript"></script>
		<!--动态js-->
		<script language="javascript" type="text/javascript">
			var org = Common.cOrg()
			var qt = {}
			var b=false;			//数据表格对象
			function load(){
		
				DWR.call("giftStorageService.getLocationAllParents",function(v){
			     	$("orgparentid").value=v;
					createTable(b);
					Common.initSql(searchForm.giftType,"gift_info_add_giftType",{},"0","1","全部");	
					Common.initSql(searchForm.subType,"gift_info_add_subType",{},"0","1","全部");  
				});
				/*DWR.call('giftStorageService.getLocationParent',function(v){
					searchForm.orgparentid.value=v;
					Common.initSql(searchForm.giftType,"gift_info_add_giftType",{},"0","1","全部");	
					Common.initSql(searchForm.subType,"gift_info_add_subType",{},"0","1","全部");  
				});*/
			
			}
			function createTable(b){
				var columns = [];
				columns[0] = {type:"radio"}		
				/*var columns = [						
					{type:"radio"},
					{title:"商品名称",width:"20%"},
					{title:"商品大类型",width:"20%"},
					{title:"商品子类型",width:"20%"},
					{title:"单位名称",width:"20%"},
					{title:"单价",width:"20%",render:function(v){return Format.formatMoney(v)}}
				]*/

				if(b){
					qt = new QueryTable("giftrule_list_query_true","searchForm","datalist",columns);
				}else{
					qt = new QueryTable("giftrule_list_query_false","searchForm","datalist",columns);
				}
			}
			function showData(){
				DWR.call("giftStorageService.getJb",$("subType").value,function(v){
		       		//createTable(v);
					b=v;
					qt.showTable();			//qt为全局的QueryTable对象
				});		
			}	
			//-------商品大类及联商品小类--------
			var subType;
			function changes(s){
				if(s){
					Common.initSql(searchForm.subType,"gift_info_add_subTypeId",{subTypeId:s},"0","1","全部");
					subType = s;
				}else{
					Common.initSql(searchForm.subType,"gift_info_add_subType",{},"0","1","全部");
				} 
			}
			//商品小类及联商品大类
			function subchanges(s){
			    if(s){
					DWR.call("giftStorageService.getParentTypeId",s,function(v){
						$("giftType").value=v.id;	
					});
				}else if(!s && subType){
					subType = null;
				}else{
					Common.initSql(searchForm.giftType,"gift_info_add_giftType",{},"0","1","全部");
				}  
			}
	
			function onSave() {
				var obj = qt.getRadioValue(true);
				if(obj==null){
					showWarning("请选择一条商品信息");return;
				}
				var v = {id : obj[0],
					name : obj[1]
				}
				dialogBackValue(v);
			}

		</script>
	</HEAD>
	<BODY class="body" onload="load()">
		<div id="listview">	
			<div class="searchForm">
				<form id="searchForm" name="searchForm">
					<input type="hidden" id=orgparentid name="orgparentid">
					<table cellSpacing=0 cellPadding=4 width="100%" border=0>
						<tr>
							<td><label>商品大类</label> <select name="giftType" onchange="changes(this.value)"></select></td>
							<td><label>商品子类</label> <select name="subType" onchange="subchanges(this.value)"></select></td>
							<td><button type="button" onclick="showData()">查 询</button></td>
						</tr>
					</table>
				</form>
			</div>
			<div id="datalist"></div>	
		</div>
	</BODY>
</HTML>